﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SinglePattern
{
    public class SingleClass
    {
        private static SingleClass uniqueInstance;

        private static readonly object locker = new object();


        //私有化构造
        private SingleClass()
        {

        }
        public void Print()
        {
            Console.WriteLine("单例模式");
        }
        /// <summary>
        /// 全局只有一个访问点
        /// </summary>
        /// <returns></returns>
        public static SingleClass GetInstance()
        {
            ///双重锁
            if (uniqueInstance == null)
                //保证多线程的时候唯一
                lock (locker)
                {
                    if (uniqueInstance == null)
                        uniqueInstance = new SingleClass();
                }
            return uniqueInstance;
        }


    }
}
